<?php
/**
 * @author 3Code Group 
 * @author Pawel Giemza
 * @version 1.0
 * @package Arrow
 * @subpackage Model
 * @link http://arrowplatform.org/
 * @copyright 2009 3code 
 * @license GNU LGPL
 * 
 * @date 2009-05-20 
*/


/**
 * Basic iterator used in all Arrow models.
 * Allows to iterate through all data fields stored in model. 
 * 
 * Check Iterator documentation for description of functions.
 */
class ArrowModelIterator implements Iterator{
	
	/**
	 * 
	 * @var array - List of fields avaliable in $host object.
	 */
	protected $fields = array();
	/**
	 * 
	 * @var object - Object whose fields are beineg iterated. 
	 */
	protected $host = null;
	
	public function __construct($host, $fieldList){
		$this->host = $host;
		$this->fields = $fieldList; 
	}

	public function objClass(){
		return get_class($this->host);
	}
	
	public function rewind() {
		reset($this->fields);
	}

	public function current() {
		$field = current($this->fields);
		if ($field !== false)
			return $this->host[$field];
		return false;
	}

	public function key() {
		$key = current($this->fields);
		return $key;
	}

	public function next() {
		$var = next($this->fields);
		if ($var !== false)		
			return $this->host[$var];
		return false;	
	}

	public function valid() {
		if( current($this->fields) )
			return true;
		return false ;  		
	}	
}
?>